﻿// <copyright file="ProductKey.cs" company="Snowman Consulting">
//     Copyright (c) 2009 Snowman Consulting. All rights reserved.
// </copyright>

namespace SnowmanConsulting.ProductKeyManager.Data
{
    using System;
    using System.ComponentModel;

    /// <summary>
    /// Product Key class
    /// </summary>
    [Serializable()]
    public class ProductKey : INotifyPropertyChanged
    {
        #region Fields

        /// <summary>
        /// The code for this product key
        /// </summary>
        private string code;

        /// <summary>
        /// Where this key is allocated to
        /// </summary>
        private string allocatedTo;

        /// <summary>
        /// The notes for this key
        /// </summary>
        private string notes;

        #endregion

        #region Events

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the code.
        /// </summary>
        /// <value>The product code.</value>
        public string Code
        {
            get
            {
                return this.code;
            }

            set
            {
                if (this.code != value)
                {
                    this.code = value;
                    this.NotifyPropertyChanged("Code");
                }
            }
        }

        /// <summary>
        /// Gets or sets the allocated to.
        /// </summary>
        /// <value>Where this key is allocated to.</value>
        public string AllocatedTo
        {
            get
            {
                if (this.allocatedTo == null)
                {
                    this.allocatedTo = string.Empty;
                }

                return this.allocatedTo;
            }

            set
            {
                if (this.allocatedTo != value)
                {
                    this.allocatedTo = value;
                    this.NotifyPropertyChanged("AllocatedTo");
                }
            }
        }

        /// <summary>
        /// Gets or sets the notes.
        /// </summary>
        /// <value>The notes for this product key.</value>
        public string Notes
        {
            get
            {
                return this.notes;
            }

            set
            {
                if (this.notes != value)
                {
                    this.notes = value;
                    this.NotifyPropertyChanged("Notes");
                }
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Notifies the property changed.
        /// </summary>
        /// <param name="info">The name of the property changed</param>
        private void NotifyPropertyChanged(string info)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}
